package o;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import com.huawei.appgallery.productpurchase.impl.cache.DpsProductDetail;
import com.huawei.appgallery.productpurchase.impl.processor.IapJumpActivity;
import com.huawei.hms.support.api.client.Status;
import com.huawei.hms.support.api.entity.iap.ConsumePurchaseReq;
import com.huawei.hms.support.api.entity.iap.GetBuyIntentWithPriceReq;
import com.huawei.hms.support.api.entity.iap.GetPurchaseReq;
import com.huawei.hms.support.api.entity.iap.OrderStatusCode;
import com.huawei.hms.support.api.iap.ConsumePurchaseResult;
import com.huawei.hms.support.api.iap.GetBuyIntentResult;
import com.huawei.hms.support.api.iap.GetPurchasesResult;
import com.huawei.hms.support.api.iap.IsBillingSupportedResult;
import com.huawei.hms.support.api.iap.json.Iap;
import com.huawei.hms.support.api.iap.json.IapApiException;
import com.huawei.updatesdk.service.otaupdate.UpdateKey;
import o.crh.b;

public class crq {
    private static int ˏ;

    public static void ˎ(Context context, int i) {
        fjo isBillingSupported;
        ˏ = i;
        if (!(context instanceof Activity)) {
            isBillingSupported = Iap.getIapClient(context).isBillingSupported();
        } else if (erz.ˎ(context, "com.huawei.hwid") < 30003000) {
            crf.ˎ.ˋ("IapProductPurchaseHelper", "hms version is low");
            cso.ˏ((Activity) context);
            cro.ˏ().ˏ(8);
            return;
        } else {
            isBillingSupported = Iap.getIapClient((Activity) context).isBillingSupported();
        }
        isBillingSupported.ˏ(new fjp<IsBillingSupportedResult>() {
            public /* synthetic */ void ˎ(Object obj) {
                ॱ((IsBillingSupportedResult) obj);
            }

            public void ॱ(IsBillingSupportedResult isBillingSupportedResult) {
                crq.ˏ();
            }
        });
        isBillingSupported.ˋ(new fjr() {
            public void ˎ(Exception exception) {
                crq.ˊ(exception);
            }
        });
    }

    private static void ˏ() {
        switch (ˏ) {
            case 1:
                cro.ˏ().ˋ();
                return;
            case 2:
                ˊ(null);
                return;
            default:
                cro.ˏ().ˏ(8);
                return;
        }
    }

    public static void ˊ(Context context, DpsProductDetail dpsProductDetail) {
        crf.ˎ.ˎ("IapProductPurchaseHelper", "Get Buy Intent.");
        csi.ˎ(b.ॱॱ, dpsProductDetail.ʼ());
        GetBuyIntentWithPriceReq getBuyIntentWithPriceReq = new GetBuyIntentWithPriceReq();
        getBuyIntentWithPriceReq.productId = dpsProductDetail.ॱ();
        getBuyIntentWithPriceReq.priceType = dpsProductDetail.ˋ();
        getBuyIntentWithPriceReq.productName = dpsProductDetail.ᐝ();
        if (dpsProductDetail.ॱॱ() == null || dpsProductDetail.ॱॱ().ˋ() == null) {
            getBuyIntentWithPriceReq.amount = dpsProductDetail.ˊ();
        } else {
            getBuyIntentWithPriceReq.amount = dpsProductDetail.ॱॱ().ˋ();
        }
        getBuyIntentWithPriceReq.country = cdn.ˏ();
        getBuyIntentWithPriceReq.currency = dpsProductDetail.ˏ();
        getBuyIntentWithPriceReq.developerPayload = dpsProductDetail.ʼ();
        if (!(context instanceof Activity)) {
            getBuyIntentWithPriceReq.sdkChannel = "1";
        } else if (dgm.ˎ((Activity) context) == dgm.ˊ()) {
            getBuyIntentWithPriceReq.sdkChannel = "3";
        } else {
            getBuyIntentWithPriceReq.sdkChannel = "1";
        }
        getBuyIntentWithPriceReq.serviceCatalog = "X50";
        fjo buyIntentWithPrice = Iap.getIapClient(context).getBuyIntentWithPrice(getBuyIntentWithPriceReq);
        buyIntentWithPrice.ˏ(new fjp<GetBuyIntentResult>() {
            public /* synthetic */ void ˎ(Object obj) {
                ˊ((GetBuyIntentResult) obj);
            }

            public void ˊ(GetBuyIntentResult getBuyIntentResult) {
                cro.ˏ().ˎ(getBuyIntentResult);
            }
        });
        buyIntentWithPrice.ˋ(new fjr() {
            public void ˎ(Exception exception) {
                crq.ˊ(exception);
            }
        });
    }

    public static void ˏ(Context context, String str) {
        crf.ˎ.ˎ("IapProductPurchaseHelper", "Consume Product");
        ConsumePurchaseReq consumePurchaseReq = new ConsumePurchaseReq();
        consumePurchaseReq.purchaseToken = str;
        fjo consumePurchase = Iap.getIapClient(context).consumePurchase(consumePurchaseReq);
        consumePurchase.ˏ(new fjp<ConsumePurchaseResult>() {
            public /* synthetic */ void ˎ(Object obj) {
                ˋ((ConsumePurchaseResult) obj);
            }

            public void ˋ(ConsumePurchaseResult consumePurchaseResult) {
                if (consumePurchaseResult.getReturnCode() == 0) {
                    cro.ˏ().ˊ();
                } else {
                    cro.ˏ().ˏ(2);
                }
            }
        });
        consumePurchase.ˋ(new fjr() {
            public void ˎ(Exception exception) {
                crq.ˊ(exception);
            }
        });
    }

    public static void ˊ(String str) {
        crf.ˎ.ˋ("IapProductPurchaseHelper", "Get the unfinished order information.");
        GetPurchaseReq getPurchaseReq = new GetPurchaseReq();
        getPurchaseReq.priceType = 0;
        if (!cgy.ˎ(str)) {
            getPurchaseReq.continuationToken = str;
        }
        fjo purchases = Iap.getIapClient(cro.ˏ().ˎ()).getPurchases(getPurchaseReq);
        purchases.ˏ(new fjp<GetPurchasesResult>() {
            public /* synthetic */ void ˎ(Object obj) {
                ˋ((GetPurchasesResult) obj);
            }

            public void ˋ(GetPurchasesResult getPurchasesResult) {
                crk.ˊ().ˊ(getPurchasesResult);
            }
        });
        purchases.ˋ(new fjr() {
            public void ˎ(Exception exception) {
                crq.ˊ(exception);
            }
        });
    }

    public static void ˊ(Exception exception) {
        if (exception instanceof IapApiException) {
            Status status = ((IapApiException) exception).getStatus();
            crf.ˎ.ˏ("IapProductPurchaseHelper", "PayStatus=" + status.getStatusCode());
            crf.ˎ.ˏ("IapProductPurchaseHelper", "PayStatusMessage=" + status.getStatusMessage());
            switch (status.getStatusCode()) {
                case OrderStatusCode.ORDER_STATE_NET_ERROR /*60005*/:
                    cso.ˊ(cro.ˏ().ˎ(), b.ˋ);
                    cro.ˏ().ˏ(2);
                    return;
                case OrderStatusCode.ORDER_HWID_NOT_LOGIN /*60050*/:
                    csi.ˋ(11);
                    ˋ();
                    return;
                case OrderStatusCode.ORDER_ITEM_ALREADY_OWNED /*60051*/:
                    crf.ˎ.ˏ("IapProductPurchaseHelper", "The product is already owned.");
                    cro.ˏ().ॱ();
                    return;
                case OrderStatusCode.ORDER_ACCOUNT_AREA_NOT_SUPPORTED /*60054*/:
                    cro.ˏ().ˏ(1);
                    return;
                case OrderStatusCode.ORDER_NOT_ACCEPT_AGREEMENT /*60055*/:
                    ˏ(status);
                    return;
                default:
                    cro.ˏ().ˏ(1);
                    return;
            }
        }
        cro.ˏ().ˏ(2);
    }

    public static void ˏ(Status status) {
        if (status.hasResolution() && cro.ˏ().ॱॱ() == 1) {
            Intent intent = new Intent(cro.ˏ().ˎ(), IapJumpActivity.class);
            if (!(cro.ˏ().ˎ() instanceof Activity)) {
                intent.addFlags(268435456);
            }
            intent.putExtra("jump_type", 2);
            Bundle bundle = new Bundle();
            bundle.putParcelable(UpdateKey.STATUS, status);
            intent.putExtra("status_bundle", bundle);
            cro.ˏ().ˎ().startActivity(intent);
            return;
        }
        cro.ˏ().ˏ(2);
    }

    public static void ˋ() {
        if (cro.ˏ().ॱॱ() == 1) {
            csq.ˊ(false);
            eoj.ˋ().ˎ("IapProductPurchaseHelper", new crx());
            eod.ॱ(cro.ˏ().ˎ());
            return;
        }
        cro.ˏ().ˏ(2);
    }
}
